package biz.datalk.industrialland.admin.modules.common.pojo.dto;

import biz.datalk.industrialland.admin.config.properties.IndustrialLandCoreProperties;
import biz.datalk.industrialland.common.util.SpringContextUtils;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.spi.group.DefaultGroupSequenceProvider;

import java.util.List;

/**
 * @author tarofang@163.com
 * @date 2024-01-15
 */
@Slf4j
public class CodeDTOGroupSequenceProvider implements DefaultGroupSequenceProvider<CodeDTO> {

    @Override
    public List<Class<?>> getValidationGroups(CodeDTO codeDTO) {
        if (log.isDebugEnabled()) {
            log.debug("CodeDTOGroupSequenceProvider#getValidationGroups ================== into");
        }
        try {
            List<Class<?>> defaultGroupSequence = Lists.newArrayList(CodeDTO.class);
            if (codeDTO == null) {
                if (log.isDebugEnabled()) {
                    log.debug("codeDTO is null.");
                }
                return defaultGroupSequence;
            }

            IndustrialLandCoreProperties sharedGarageAdminProperties = SpringContextUtils.getBean(IndustrialLandCoreProperties.class);
            Boolean loginUseImgCaptcha = sharedGarageAdminProperties.getLoginUseImgCaptcha();
            if (loginUseImgCaptcha != null && loginUseImgCaptcha) {
                defaultGroupSequence.add(CodeDTO.ChkCaptcha.class);
            }
            return defaultGroupSequence;
        } finally {
            if (log.isDebugEnabled()) {
                log.debug("CodeDTOGroupSequenceProvider#getValidationGroups ================== out");
            }
        }
    }
}
